package com.min.star.service.impl;

import java.util.Arrays;
import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.min.star.mapper.StudentMapper;
import com.min.star.model.Student;
import com.min.star.service.IStudentService;

@Service
public class StudentServiceImpl implements IStudentService {

	@Autowired
	private StudentMapper studentMapper;

	@Override
	public List<Student> selectStudentList() {
		return this.studentMapper.selectList(null);
	}

	@Override
	public Student login(Student student) {
		return this.studentMapper.login(student);
	}

	@Override
	public Page<Student> findPage(Page<Student> page, Student student) {
		return studentMapper.findPage(page, student);
	}

	@Override
	public int delete(Long id) {
		return this.studentMapper.deleteById(id);
	}

	@Override
	public int delete(String ids) {
		return this.studentMapper.deleteBatchIds(Arrays.asList(ids.split(",")));
	}

	@Override
	public int add(Student student) {
		return this.studentMapper.insert(student);
	}

	@Override
	public Student save(Student student) {
		// 当对象student被新增后，只需获取一下该对象的id,
		int ret = studentMapper.insert(student);
		Long id = student.getId();
		Student info = studentMapper.selectById(id);
		return info;

	}

	@Override
	public Student update(@Valid Student student) {
		int ret = this.studentMapper.updateById(student);
		return this.studentMapper.selectById(student.getId());
	}

	@Override
	public Student selectById(Long id) {
		return studentMapper.selectById(id);
	}

	@Override
	public int editInfo(Object name, Object value, Long id) {
		return studentMapper.editInfo(name,value,id);
	}


}
